import { globSync } from "glob";
import path, { resolve } from "path";
import { fileURLToPath } from "url";
import alias from "@rollup/plugin-alias";
import nodeResolve from "@rollup/plugin-node-resolve";

const input = Object.fromEntries(
  globSync("src/**/*.js").map((file) => [
    path.relative(
      "src",
      file.slice(0, file.length - path.extname(file).length)
    ),
    fileURLToPath(new URL(file, import.meta.url)),
  ])
);

export default {
  input,
  output: {
    format: "es",
    dir: "dist",
    preserveModules: true,
  },
  plugins: [
    // nodeResolve({
    //   modulesOnly: true,
    // }),
    alias({
      entries: [{ find: "@", replacement: resolve("src") }],
    }),
  ],

  treeshake: "smallest",
};
